<template>
  <div id="show_info">
    <div class="show_info">
      <div class="show_info_header">
        <div class="show_info_header_title">
          <template v-if="roomType === 'group'">
            群聊信息
          </template>
          <template v-else-if="roomType === 'double'">
            好友信息
          </template>
        </div>
        <div class="show_info_header_icon" @click="showMore">
          <i class="iconfont icon-more"></i>
        </div>
      </div>
      <div class="show_info_body">
        <template v-if="roomType === 'group'">
          <div class="show_info_body_item">
            <span>房间ID：</span>{{ roomInfo.room_id }}
          </div>
          <div class="show_info_body_item">
            <span>创建时间：</span>{{ roomInfo.created_at }}
          </div>
          <div class="show_info_body_item">
            <span>状态：</span>{{ roomInfo.is_active ? '活跃' : '非活跃' }}
          </div>
          <div class="show_info_body_item">
            <span>类型：</span>{{ roomInfo.type }}
          </div>
        </template>

        <template v-else-if="roomType === 'double' && friendInfo">
          <div class="show_info_body_item">
            <span>用户名：</span>{{ friendInfo.username }}
          </div>
          <div class="show_info_body_item">
            <span>ID：</span>{{ friendInfo.id }}
          </div>
          <div class="show_info_body_item">
            <span>邮箱：</span>{{ friendInfo.email }}
          </div>
          <div class="show_info_body_item">
            <span>性别：</span>{{ friendInfo.sex }}
          </div>
          <div class="show_info_body_item">
            <span>年龄：</span>{{ friendInfo.age }}
          </div>
          <div class="show_info_body_item">
            <span>简介：</span>{{ friendInfo.introduction }}
          </div>
        </template>
        <template v-else>
          <div class="show_info_body_item">
            无可用信息
          </div>
        </template>
        <div v-for="(i,index) in funccollections" :key="index" class="show_info_body_item">
          <button @click="i.onclick">
            {{i.name}}
          </button>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import {inject,ref, computed, watch, onMounted } from "vue"
import { get_room_info_all_by_room_id_type } from "@/api/chat/room"

const chat = inject('chat')()
const info = ref(null)
const singleinfo = computed(() => { 
  return chat.value.get_current_show_info_room_info()
})
watch(() => singleinfo.value, async (newV, oldV) => { 
  console.log(newV)
  info.value =await get_room_info_all_by_room_id_type(singleinfo.value.room_id,
    singleinfo.value.type,
    chat.value.get_user_info()?.id,
  )
  console.log(info.value)
})
const funccollections = ref([])
const roomType = computed(() => info.value?.room_info?.type || "")
const roomInfo = computed(() => info.value?.room_info || {})
const friendInfo = computed(() => {
  if (roomType.value === 'double') {
    return info.value?.friend_info || {}
  }
  return null
})
onMounted(async() => { 
  console.log(singleinfo.value)
  info.value =await get_room_info_all_by_room_id_type(singleinfo.value.room_id,
    singleinfo.value.type,
    chat.value.
    get_user_info()?.id,
  )
  console.log(info.value)
})

</script>

<style scoped>
#show_info {
  display: flex;
  justify-content: center;
  align-items: center;
}
.show_info {
  background: #fff;
  border-radius: 10px;
  padding: 18px 24px;
  min-width: 320px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.08);
  font-family: "Microsoft YaHei", Arial, sans-serif;
}
.show_info_header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #f0f0f0;
  padding-bottom: 10px;
}
.show_info_header_title {
  font-size: 20px;
  font-weight: 600;
  color: #2c3e50;
}
.show_info_header_icon {
  cursor: pointer;
  font-size: 18px;
  color: #8a8a8a;
  transition: color 0.2s;
}
.show_info_header_icon:hover {
  color: #409eff;
}
.show_info_body {
  margin-top: 16px;
}
.show_info_body_item {
  display: flex;
  align-items: center;
  margin-bottom: 10px;
  font-size: 15px;
  color: #444;
}
.show_info_body_item span {
  color: #888;
  margin-right: 8px;
  min-width: 72px;
  display: inline-block;
}
.show_info_body_item button {
  margin-left: 10px;
  padding: 5px 16px;
  background: #409eff;
  border: none;
  color: #fff;
  border-radius: 5px;
  cursor: pointer;
  transition: background 0.2s;
}
.show_info_body_item button:hover {
  background: #337ecc;
}
</style>